package com.chapter14.Map_;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 宋鑫宇
 * @version 1.0
 * Map和Collection并列存在，用于保存具有映射关系的数据
 * 演示Map接口常用方法
 */
public class Map_ {
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put("1",new Book("",100));
        map.put("1","123");
        map.put("2","234");
        map.put("3","234");
        map.put("4",null);
        map.put(null,"456");
        map.put("5","567");
        System.out.println(map);
        //删除Key为4的元素
        map.remove("4");
        System.out.println(map);
        //根据Key获取值
        System.out.println(map.get(2));
        //获取元素个数
        System.out.println(map.size());
        //清空集合
//        map.clear();
//        System.out.println(map);
        //查找Key是否存在
        System.out.println(map.containsKey(null));

    }
}
class Book{
    private String name;
    private int num;

    public Book(String name, int num) {
        this.name = name;
        this.num = num;
    }
}